package com.third.customer.site;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.third.customer.model.dao.UserDao;
import com.third.customer.service.client.RedisClient;
import com.third.customer.site.support.AuthInterceptor;
import com.third.customer.site.support.HttpInterceptor;
import com.third.customer.site.support.UserResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * Created by hehuaichun on 2020/5/20.
 */
@Configuration
public class WebAppConfiguration extends WebMvcConfigurerAdapter {

    @Autowired
    private RedisClient redisClient;

    @Autowired
    private UserDao userDao;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthInterceptor(redisClient, userDao));
        registry.addInterceptor(new HttpInterceptor());
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new UserResolver());
    }
}
